<?php
/* All includes needed */
session_start();

//ERROR LOGGING
ini_set("display_errors", 1); //activeer de display_error 
//ERROR LOGGING

include_once('./includes/func_pagetimer.php');

ini_set("include_path", ".:..:../..");

require('./core/Smarty_oRs.php');
require('./includes/config.php');
require('./includes/rights.php');
require('./includes/func_database.php');
require('./includes/func_debug.php');
require('./includes/func_news.php');
require('./includes/func_menu.php');
require('./includes/func_player.php');
require('./includes/func_rp.php');
require('./includes/func_rp_category.php');
require('./includes/func_raid.php');
require('./includes/func_signups.php');
require('./includes/func_downloads.php');
require('./includes/func_login.php');
require('./includes/func_teams.php');
require('./includes/func_static.php');
require('./includes/func_player_attributes.php');
require('./includes/func_attributes.php');
require('./includes/func_event.php');
require('./includes/func_class_roles.php');
require('./includes/func_raid_roles.php');
require('./includes/func_shouts.php');
require('./includes/func_profile.php');
require('./includes/func_settings.php');
require('./includes/libchart/classes/libchart.php');



$pagegen = new page_gen();
$pagegen->round_to = 7;
$pagegen->start();


$dbh = initConnection();

$debug = new debug();
$player = new player();
$rp = new rp();
$rp_category = new rp_category();
$player_attribute = new player_attribute();
$attribute = new attribute();
$team = new team();
$raid = new raid();
$signup = new signup();
$menu = new menu();
$user = new User();
$download = new download();
$event = new event();
$date = gmdate("'Y-m-d'");
$class_role = new class_role();
$raid_role = new raid_role();
$profile = new profile();
$settings = new settings();

/* connect to the database */
$races = array("Dwarf" => "Dwarf", "Human" => "Human", "Night Elf" => "Night Elf", "Gnome" => "Gnome", "Draenei" => "Draenei");

$classes = $class_role->getClasses();

$full_classes = $class_role->getFullClasses();

//$classes = array("1" => "Mage","2" => "Paladin","3" => "Hunter","4" => "Warrior","5" => "Rogue","6" => "Priest","7" => "Druid", "8" => "Warlock", "9" => "Shaman", "10" => "Death knight");

/* Initialize the Smary class */
$smarty = new Smarty_oRs;

if ($_SESSION['uid'] == 0) {
	session_defaults();
}

if (isset($_POST['username_login'])) {

	if ($_POST['save'] == 'on') {
		$remember = true;
	} else {
		$remember = false;
	}

	$username_login = $_POST['username_login'];
	$password_login =  $_POST['password_login'];

	$logged_in = $user->_checkLogin($username_login, $password_login, $remember);

}

if(isset($_GET['remove_player'])) {
	if(is_allowed(3)) {
	$player_id = abs($_GET['remove_player']);

	$player->remove($player_id);

	$message = "The player has been removed from the system";

	}
}

if (isset($_GET['page'])) {

	$locator = $_GET['page'];

	if ($locator == "forum") {
		$main_page = 'forum.php';
	} elseif ($locator == "logout") {
		setcookie($_COOKIE_NAME, "empty", time() - 9000000, '/');
		session_defaults();
		$main_page = 'logout.php';

	} else {
		$menu = new menu;

		$page = $menu->getAction($locator);

		$level = $menu->getLevel($page);

		if (is_allowed($level)) {
			if (!file_exists($page)) {
				$main_page = 'error.php';
			} else {

				$main_page = $page;
			}
		} else {
			$main_page = 'login.php';
		}
	}

}
else
{
	$main_page = 'main.php';
}

$smarty->assign('USER_RIGHTS', $USER_RIGHTS);

$smarty->display('index.tpl', $_SESSION['uid']);

/* Start including all content files based on the url */
require('logo.php');

require('banner.php');

require('menu_top.php');

require('container_start.php');

require('left_column.php');

require($main_page);

//require('right_column.php');

require('footer.php');

require('container_end.php');







?>